package com.wmeimob.fastboot.jiubei.service;

import com.wmeimob.fastboot.jiubei.entity.ShopGoodsBrowseRecord;
import com.wmeimob.fastboot.jiubei.mapper.ShopGoodsBrowseRecordMapper;
import com.wmeimob.fastboot.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ShopGoodsBrowseRecordServiceImpl
 * @Description  商品浏览记录 服务类实现
 * @Author wjt
 * @Date Mon Sep 07 23:58:44 CST 2020
 * @version 1.0
 **/

@Service
@Transactional(rollbackFor={Exception.class})
@Slf4j
public class ShopGoodsBrowseRecordServiceImpl implements ShopGoodsBrowseRecordService {

    @Resource
    private ShopGoodsBrowseRecordMapper shopGoodsBrowseRecordMapper;


    @Override
    public List<ShopGoodsBrowseRecord> list(ShopGoodsBrowseRecord shopGoodsBrowseRecord) {
        Example example = new Example(ShopGoodsBrowseRecord.class);
        Example.Criteria criteria = example.createCriteria();
	  if(!StringUtils.isEmpty(shopGoodsBrowseRecord.getId())){
            criteria.andEqualTo("id",shopGoodsBrowseRecord.getId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsBrowseRecord.getName())){
            criteria.andLike("name",StringUtils.fullFuzzy(shopGoodsBrowseRecord.getName()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsBrowseRecord.getUserId())){
            criteria.andEqualTo("userId",shopGoodsBrowseRecord.getUserId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsBrowseRecord.getGmtCreate())){
            criteria.andEqualTo("gmtCreate",shopGoodsBrowseRecord.getGmtCreate());
	  }
        example.orderBy("id").desc();
        List<ShopGoodsBrowseRecord> shopGoodsBrowseRecords = shopGoodsBrowseRecordMapper.selectByExample(example);
        return shopGoodsBrowseRecords;
    }

    @Override
    public ShopGoodsBrowseRecord queryShopGoodsBrowseRecordById(Object id) {
        return shopGoodsBrowseRecordMapper.selectByPrimaryKey(id);
    }


	@Override
    public void addShopGoodsBrowseRecord(ShopGoodsBrowseRecord shopGoodsBrowseRecord) {
	  shopGoodsBrowseRecord.setGmtCreate(new Date());
        shopGoodsBrowseRecordMapper.insertSelective(shopGoodsBrowseRecord);
    }

    @Override
    public void removeShopGoodsBrowseRecord(Long id) {
	  ShopGoodsBrowseRecord shopGoodsBrowseRecord = new ShopGoodsBrowseRecord();
	  shopGoodsBrowseRecord.setId(id);
        shopGoodsBrowseRecordMapper.updateByPrimaryKeySelective(shopGoodsBrowseRecord);
    }

    @Override
    public void modifyShopGoodsBrowseRecord(ShopGoodsBrowseRecord shopGoodsBrowseRecord) {
        shopGoodsBrowseRecordMapper.updateByPrimaryKeySelective(shopGoodsBrowseRecord);
    }

}
